package thesis;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.LinkedList;
import java.util.List;


import com.aliasi.util.Pair;

import experiment.Dimension;

public class DataObject implements Comparable<DataObject> {
	private long dbId;
	private int internId;
	private double quality = 0;
	private double div = 0;
	private double qual;
	private double up;
	private double origCov;
	private boolean inS = false;
	private String text;
	private Date date;
	public Date getDate() {
		return date;
	}

	public void setDate(Date date) {
		this.date = date;
	}

	private ArrayList<Pair<Double, ArrayList<Double>>> rels = new ArrayList<Pair<Double, ArrayList<Double>>>();
	private ArrayList<Pair<Double, InfoUnit>> units = new ArrayList<Pair<Double, InfoUnit>>();

	public LinkedList<DataObject> group = new LinkedList<DataObject>();

	public String getKey() {
		String key = "";
		key += DataUtil.map2discrete(quality);
		for (Pair<Double, ArrayList<Double>> pair : rels) {
			for (Double prob : pair.b()) {
				key += DataUtil.map2discrete(prob);
			}
		}
		return key;
	}

	public void reset() {
		div = 0;
		quality = 0;
		inS = false;
		rels.clear();
		units.clear();
		// TODO Auto-generated method stub

	}

	public boolean isInS() {
		return inS;
	}

	public void setInS(boolean inS) {
		this.inS = inS;
	}

	public ArrayList<Pair<Double, InfoUnit>> getUnits() {
		return units;
	}

	public void addUnit(InfoUnit unit, double prob) {
		units.add(new Pair<Double, InfoUnit>(prob, unit));
	}

	public double dist(DataObject t) {
		double dist = 0;
		double totalWeight = 0;
		for (int i = 0; i < rels.size(); i++) {
			double weight = rels.get(i).a(); // dimension weight
			dist += weight
					* DataUtil.cosDistance(rels.get(i).b(), t.rels.get(i).b());
			totalWeight += weight;
		}
		return dist / totalWeight;
	}

	public void initRels(
			final List<Dimension> dimensions,
			final ArrayList<Double> weights) {
		for (int i = 0; i < dimensions.size(); i++) {
			rels.add(new Pair<Double, ArrayList<Double>>(weights.get(i),
					new ArrayList<Double>(dimensions.get(i).value2obj.size())));
		}
	}

	public void addRel(int dimensionId, double relScore) {
		rels.get(dimensionId).b().add(relScore);
	}

	public double getRel(int dimId, int vId) {
		return rels.get(dimId).b().get(vId);
	}

	public String getText() {
		return text;
	}

	public void setText(String text) {
		this.text = text;
	}

	public double getOrigCov() {
		return origCov;
	}

	public void setOrigCov(double origCov) {
		this.origCov = origCov;
	}

	public double getUp() {
		return up;
	}

	public void setUp(double up) {
		this.up = up;
	}

	public double getDiv() {
		return div;
	}

	public void setDiv(double div) {
		this.div = div;
	}

	public double getQual() {
		return qual;
	}

	public void setQual(double qual) {
		this.qual = qual;
	}

	public double getCov() {
		return cov;
	}

	public void setCov(double cov) {
		this.cov = cov;
	}

	private double cov;

	public DataObject(long tweetId) {
		this.dbId = tweetId;
	}

	public long getDbId() {
		return dbId;
	}

	public void setDbId(long dbId) {
		this.dbId = dbId;
	}

	public double getQuality() {
		return quality;
	}

	public void setQuality(double quality) {
		this.quality = quality;
	}

	public int getInternId() {
		return internId;
	}

	public void setInternId(int internId) {
		this.internId = internId;
	}

	public ArrayList<Pair<Double, ArrayList<Double>>> getRels() {
		return rels;
	}

	@Override
	public int compareTo(DataObject o) {
		// TODO Auto-generated method stub
		if (this.getUp() > o.getUp())
			return -1;
		else if (this.getUp() == o.getUp())
			return 0;
		else
			return 1;
	}

}
